<template>
	<view class="antique">
		<Navbar :lock="lock">古董市场</Navbar>
		<scroll-view scroll-y class="scroll_view">
			<view class="content">
				<view class="list">
					<view class="item" v-for="item in list" @click="look(item)">
						<image :src="item.img"></image>
					</view>
				</view>
				<view class="desc">
					<u-parse :content="content" :previewImg="false"></u-parse>
				</view>
			</view>
		</scroll-view>
		<u-popup :show="popup_show" bgColor="transparent" mode="center" @close="close">
			<AntiqueSelect :item="item" @close="close" @confirm="confirm" v-if="popup==1" />
			<Identify :img="img" @close="close" @success="success" v-if="popup==2" />
			<AntiqueResult :list="res" @close="close" v-if="popup==3" />
			<!-- <IdentifyResult :name="name" :cover="cover" @close="close" v-if="popup==3" /> -->
		</u-popup>
	</view>
</template>

<script>
	import {
		antiqueRole,
		antiqueIdentify
	} from '@/request/api.js';
	// import {
	// 	captchaAppId
	// } from "@/utils/config";
	import AntiqueSelect from '@/components/home/AntiqueSelect.vue';
	import Identify from '@/components/home/Identify.vue';
	import IdentifyResult from '@/components/home/IdentifyResult.vue';
	import AntiqueResult from '@/components/home/AntiqueResult.vue';

	export default {
		components: {
			AntiqueSelect,
			Identify,
			IdentifyResult,
			AntiqueResult
		},
		data() {
			return {
				lock: false,

				list: [],
				content: "",

				img: '',
				item: {},
				popup_show: false,
				show: false,
				popup: 1,

				res: []
			}
		},
		onLoad() {
			this.getList();
		},
		methods: {
			async getList() {
				let {
					role,
					setting
				} = await antiqueRole();
				this.list = role;
				this.content = setting?.content;
			},
			look(item) {
				this.img = item.img;
				this.item = item;
				this.open(1);
			},
			open(index) {
				this.popup = index;
				this.popup_show = true;
			},
			close() {
				if (this.popup == 2) return false;
				this.popup_show = false;
			},
			async confirm(ids) {
				if (this.is_click) {
					this.$u.toast("请等待服务器结果");
					return false;
				}
				this.is_click = true;
				await antiqueIdentify({
					role_id: this.item.id,
					order_id: ids
				}, {
					custom: {
						catch: true
					}
				}).then(res => {
					this.res = res;
					this.open(2);
					this.lock = true;
					this.is_click = false;
				}).catch(() => {
					this.is_click = false;
				});
			},
			success() {
				this.open(3);
				this.lock = false;
			}
		}
	}
</script>

<style scoped lang="scss">
	.antique {
		height: 100vh;
		background: #29170D;
		overflow: hidden;

		.scroll_view {
			height: calc(100vh - #{$navbarHeight});

			.content {
				height: 1524rpx;
				background: url(#{$baseImageUrl}/bg/bg6.png) no-repeat;
				background-size: 100% 100%;

				.list {
					padding: 40rpx;
					box-sizing: border-box;
					display: flex;
					flex-wrap: wrap;
					justify-content: space-between;

					.item {
						width: 204rpx;
						height: 204rpx;

						image {
							width: 100%;
							height: 100%;
						}
					}
				}

				.desc {
					width: 100%;
					// height: 480rpx;
					// padding: 40rpx 80rpx 20rpx;
					// box-sizing: border-box;
					// background: url(#{$baseImageUrl}/home/desc.png) no-repeat;
					// background-size: 100% 100%;

					// .title {
					// 	line-height: 28rpx;
					// 	text-align: center;
					// 	color: #000000;
					// 	font-size: 28rpx;
					// 	font-weight: 400;
					// 	font-family: SimSun;
					// }

					.u_parse {
						color: #333;
						font-family: SimSun;
						padding-top: 44rpx;
					}
				}
			}
		}
	}
</style>